#!/bin/bash
#
# Copyright 2015-2017 Adrian DC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# === Standalone Source Helper ===
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_adb_host.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_adb_tools.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_adb_installers.rc)
# source <(curl -Ls https://github.com/AdrianDC/android_development_shell_tools/raw/master/android_release_helpers.rc)

# === Ninja Disabler ===
function noninja()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: noninja <command...> (Run command without ninja)';
    echo '';
    return;
  fi;

  # Run command without ninja
  export USE_NINJA=false;
  export USE_SOONG_UI=false;
  "${@}";
  export USE_NINJA=;
  export USE_SOONG_UI=;
}

# === Build Without Ninja ===
function mmo()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: mmo <command...> (Build module without ninja)';
    echo '';
    return;
  fi;

  # Build module without ninja
  export USE_NINJA=false;
  export USE_SOONG_UI=false;
  mmm "${@}";
  export USE_NINJA=;
  export USE_SOONG_UI=;
}

# === Build & Install Without Ninja ===
function mmi()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: mmi <command...> (Build & install module without ninja)';
    echo '';
    return;
  fi;

  # Build & install module without ninja
  export USE_NINJA=false;
  export USE_SOONG_UI=false;
  adbi mmm "${@}";
  export USE_NINJA=;
  export USE_SOONG_UI=;
}

# === Build & Listen Without Ninja ===
function mmil()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: mmil <command...> (Build & list module without ninja)';
    echo '';
    return;
  fi;

  # Build & list module without ninja
  export USE_NINJA=false;
  export USE_SOONG_UI=false;
  adbil mmm "${@}";
  export USE_NINJA=;
  export USE_SOONG_UI=;
}

# === CCache Disabler ===
function noccache()
{
  # Usage
  if [ -z "${1}" ]; then
    echo '';
    echo ' Usage: noccache <command...> (Run command without CCache)';
    echo '';
    return;
  fi;

  # Run command without CCache
  local use_ccache=${USE_CCACHE};
  export USE_CCACHE=0;
  "${@}";
  export USE_CCACHE=${use_ccache};
}
